$(document).ready(function() {	
	$("#frmAdd").validate({
		errorClass		: 'errorMessage',
		errorElement	: 'span',
		onfocusout		: false,
		onkeyup			: false,
		rules: {
			pcategoryid:{
				required 			: true
			},
			psubcategoryid:{
				required 			: true
			},
			pname:{
				required 			: true,
				minlength			: 3
			},
			pprice: {
				required			: true,
				min					: 1
			},
			pprice_sale: {
				required			: true,
				min					: 1
			},
			pvalue: {
				required			: true,
				min					: 1
			},
			pimage: {
				required			: true,
				validFormat			: true,
				validSize			: true
			},
			pimage_exp: {
				required			: true,
				validExpFormat		: true,
				validExpSize		: true
			}
		},
		messages: {
			pcategoryid:{
				required 			: category_required
			},
			psubcategoryid:{
				required 			: sub_category_required
			},
			pname:{
				required 			: name_required,
				minlength			: name_minlength
			},
			pprice: {
				required			: price_required,
				min					: price_min
			},
			pprice_sale: {
				required			: price_sale_required,
				min					: price_sale_min
			},
			pvalue: {
				required			: value_required,
				min					: value_min
			},
			pimage: {
				required			: image_required,
				validFormat			: image_format,
				validSize			: image_size
			},
			pimage_exp: {
				required			: image_exp_required,
				validExpFormat		: image_format,
				validExpSize		: image_size
			}
		},
		errorPlacement: function(label, element) {			
			var id = element.attr('id');			
			label.insertAfter($('#' + id));			
		},
		submitHandler: function(form) {				
			form.submit();
		}
	});	
	$.validator.addMethod('validFormat', function() {
		var strLinkImage = $('#pimage').val();
		return validateImage(strLinkImage);
	});
	$.validator.addMethod('validSize', function() {
		return validateImgSize("pimage");
	});
	$.validator.addMethod('validExpFormat', function() {
		var strLinkImage = $('#pimage_exp').val();
		return validateImage(strLinkImage);
	});
	$.validator.addMethod('validExpSize', function() {
		return validateImgSize("pimage_exp");
	});
});
loadSub = function(intValue, strDiv) {
	$.getJSON(
		HOST_BACKEND + 'ajax/category?type=9&parentid=' + intValue + '&callback=?',		
		function(response) {				
			$('#'+strDiv).html(response['data']);
		}
	);
}